import React from 'react'
import ReactPullLoad, { STATS } from 'react-pullload'
import $ from '../hml'
class Xia extends React.Component {
    constructor(props) {
        super()
    }
    handleAction = (action) => {
        console.info(action, this.state.action, action === this.state.action);
        //new action must do not equel to old action
        if (action === this.state.action) {
            return false
        }

        if (action === STATS.refreshing) { //刷新
            this.handRefreshing();

        } else if (action === STATS.loading) { //加载更多
            this.handLoadMore();
        } else {
            //DO NOT modify below code
            this.setState({
                action: action
            })
        }
    }
    //刷新
    handRefreshing = () => {
        if (STATS.refreshing === this.state.action) {
            return false
        }
        setTimeout(() => {
            //refreshing complete
            this.setState({
                hasMore: true,
                action: STATS.refreshed
            });
        }, 2000)
        this.setState({
            action: STATS.refreshing
        })
    }
    //加载更多
    handLoadMore = () => {
        if (STATS.loading === this.state.action) {
            return false
        }
        setTimeout(() => {
            if (this.state.isMore === 0) {
                this.setState({
                    action: STATS.reset,
                    hasMore: false
                });
            } else {
                var n = this.state.page;
                n++;
                $.getApi2({
                    //     type: "POST",
                    //     url: httphead + "/author/goods/getList",
                    //     data: {
                    //         page: n,
                    //         end: 10,
                    //         cateIds: catAllId,
                    //         keyword: this.state.value
                    //     },
                    //     headers: {
                    //         Authorization: headers_vendor
                    //     },
                    type: "POST",
                    url: '/home/mediareports',
                    data: {
                        page_number: '1',
                        page_size: '10',
                    },
                    headers: {

                    },
                    success: function (data) {

                        if (data.code == 100) {
                            var nData = this.state.goodList.concat(data.data.goodsList);
                            this.setState({
                                goodList: nData,
                                action: STATS.reset,
                                isMore: data.data.isMore,
                                page: n
                            })
                        } else if (data.code == 500) {
                            window.location.href = "/";
                        } else {
                            alert(data.message);
                        }
                    }.bind(this)
                })
            }
        }, 500)

        this.setState({
            action: STATS.loading
        })
    }
    render() {
        return (
            <div>
                123
                <ul>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                    <li>123</li>
                </ul>
            </div>
        )
    }
}
export default Xia